package cn.zyy.hotel.service.impl;

import cn.zyy.hotel.dao.ChartsMapper;
import cn.zyy.hotel.dao.RoomTypeMapper;
import cn.zyy.hotel.entity.RoomType;
import cn.zyy.hotel.service.ChartsService;
import cn.zyy.hotel.vo.PieChartsVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ChartsServiceImpl implements ChartsService {

    @Resource
    private ChartsMapper chartsMapper;

    @Resource
    private RoomTypeMapper roomTypeMapper;

    //查询每个年度总营业额
    public List<Map> getTotalPriceByYear() {
        return chartsMapper.getTotalPriceByYear();
    }

    //根据指定的年份统计每个月的营业额
    public List<Double> getTotalPriceByYearOfMonth(String year) {
        ArrayList<Double> doubles = new ArrayList<Double>();
        String month;
        for (int i = 1; i < 13; i++) {
            if (i<10){
                month = "0"+i;
            }else {
                month = String.valueOf(i);
            }
            Double price = chartsMapper.getTotalPriceByYearOfMonth(year, month);
            if (price == null){
                doubles.add(0D);
            }else {
                doubles.add(price);
            }
        }
        return doubles;
    }

    //根据指定的年份统计该年份下每个季度的营业额
    public List<Map> getQuarterTotalPriceByYear(String year) {
        return chartsMapper.getQuarterTotalPriceByYear(year);
    }

    //根据年月统计每个房型的预定数量
    public List<PieChartsVO> getRoomTypeCountByYearAndMonth(String year) {
        return chartsMapper.getRoomTypeCountByYearAndMonth(year);
    }

    //查询当天开房记录
    public List<PieChartsVO> getCurrentDateHotelByDate(String date) {
        return chartsMapper.getCurrentDateHotelByDate(date);
    }

    //统计房型销量
    @Override
    public Map<String, List> getRoomTypeList() {
        List<RoomType> roomTypeList = roomTypeMapper.selectRoomTypeList(null);
        HashMap<String, List> map = new HashMap<>();
        ArrayList<String> names = new ArrayList<>();
        ArrayList<Integer> values = new ArrayList<>();
        for (RoomType roomType : roomTypeList) {
            names.add(roomType.getTypeName());
            values.add(roomType.getReservedNum());
        }
        map.put("roomType",names);
        map.put("values",values);
        return map;
    }


}
